package Game

import (
	"GameGo/config"
	"GameGo/po"
	"GameGo/tool"
	"github.com/hajimehoshi/ebiten/v2/audio"
)

func InitGame() *po.Game {
	tool.InitFont()

	player := po.NewPlayer(tool.ReadFileToImg("player.png"),
		208, 560, config.PlayerHP, config.PlayerHP)
	bulletImg := tool.ReadFileToImg("bullet.png")
	enemyImg := tool.ReadFileToImg("enemy.png")
	enemyBulletImg := tool.ReadFileToImg("enemy_bullet.png")
	enemyTrailImg := tool.ReadFileToImg("effect_purple.png")
	playerTrailImg := tool.ReadFileToImg("effect_yellow.png")

	audioCtx := audio.NewContext(44100)
	soundHit := tool.ReadFileOgg(audioCtx, "hit.ogg")
	soundHit.SetVolume(config.Audio / 2)
	soundShot := tool.ReadFileOgg(audioCtx, "shot.ogg")
	soundShot.SetVolume(config.Audio / 2)
	player.SoundShot = soundShot
	bgm := tool.ReadBGM(audioCtx, "bgm.ogg")
	bgm.SetVolume(config.Audio)
	soundOut := tool.ReadFileOgg(audioCtx, "out.ogg")
	soundOut.SetVolume(config.Audio)
	soundShou := tool.ReadFileOgg(audioCtx, "shou.ogg")
	soundShou.SetVolume(config.Audio)

	shader := tool.ReadShader("wave.shader")
	return &po.Game{
		Player:         *player,
		GameLevel:      config.GameLevel,
		Shader:         shader,
		BulletImg:      bulletImg,
		EnemyImg:       enemyImg,
		EnemyTrailImg:  enemyTrailImg,
		PlayerTrailImg: playerTrailImg,
		Enemies:        []po.Enemy{},
		Bullets:        []po.Bullet{},
		EnemyBulletImg: enemyBulletImg,
		EnemyNum:       []int{config.OrdinaryEnemy, config.EliteEnemy, config.Boss},
		Audio: po.Audio{
			AudioContext: audioCtx,
			SoundHit:     soundHit,
			Bgm:          bgm,
			SoundOut:     soundOut,
			SoundShou:    soundShou,
		},
	}
}
